package com.qire.manhua.dal.service;

import com.qire.antsbinder.dal.DataService;
import com.qire.antsbinder.dal.annotation.StrategyAnnotation;
import com.qire.common.constant.Url;
import com.qire.common.dal.WarehouseFactory;
import com.qire.common.model.entity.UserEntity;
import com.qire.common.utils.ToastHelper;
import com.qire.common.widget.snackbar.Prompt;
import com.qire.manhua.dal.IComicDataDAL;
import com.qire.manhua.dal.ICommentDataDAL;
import com.qire.manhua.model.viewModel.impl.ComicDetailIntroductionViewModel;
import com.qire.manhua.model.vo.OkResponseVO;
import com.qire.manhua.model.vo.RandomRecommendVO;

import java.util.List;

/**
 * 漫画详情页-简介数据服务
 */
public class ComicDetailIntroductionService extends DataService {

    private final IComicDataDAL comicDataDAL = WarehouseFactory.create(this, IComicDataDAL.class);
    private final ICommentDataDAL commentDataDAL = WarehouseFactory.create(this, ICommentDataDAL.class);

    private final ComicDetailIntroductionViewModel viewModel;

    public ComicDetailIntroductionService(ComicDetailIntroductionViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /**
     * 更需漫画ID检索类型随机推荐漫画
     * @param bookId 漫画ID
     */
    public void randomRecommend(int bookId) {
        comicDataDAL.fetchRandomRecommend(bookId, UserEntity.self.getEnablePreferences());
    }
    @StrategyAnnotation(event = Url.comicBookDetailCommend)
    public void randomRecommendApiCallBack(List<RandomRecommendVO> dataVoList, boolean isCache) {
        if(dataVoList == null || dataVoList.isEmpty()) {
            return;
        }

        viewModel.clearLikeList();
        for(int index = 0; index < dataVoList.size(); index++) {
            RandomRecommendVO recommendVO = dataVoList.get(index);
            viewModel.addLikeItemViewModel(index, recommendVO.id, recommendVO.book_name, recommendVO.book_unruly, recommendVO.tags);
        }
        viewModel.refreshLikeAdapter();
    }


    /** 点赞给喜欢的评论*/
    public void voteToGiveLikeComment(int bookId, int commentId) {
        commentDataDAL.voteToGiveLikeComment(bookId, commentId);
    }
    @StrategyAnnotation(event = Url.comment_like)
    public void voteToGiveLikeCommentApiCallBack(OkResponseVO dataVO, boolean isCache) {
        ToastHelper.showSnackBar(dataVO.ok, Prompt.SUCCESS);
    }


    /**
     * 举报评论
     * @see ICommentDataDAL#complaintComment(int, int, int, String)
     */
    public void complaintComment(int bookId, int commentId, int reportType, String content) {
        commentDataDAL.complaintComment(bookId, commentId, reportType, content);
    }
    @StrategyAnnotation(event = Url.comment_report)
    public void complaintCommentApiCallBack(OkResponseVO dataVO, boolean isCache) {
        if(dataVO.isOK()) {
            ToastHelper.showSnackBar("举报成功", Prompt.SUCCESS);
        } else {
            ToastHelper.showSnackBar("举报失败", Prompt.ERROR);
        }
    }

}
